package com.kantboot.business.gc.service.impl;

import com.kantboot.business.gc.domain.dto.BusGcCollectSearchUserDTO;
import com.kantboot.business.gc.domain.entity.BusGcUserOpenGame;
import com.kantboot.business.gc.repository.BusGcUserOpenGameRepository;
import com.kantboot.business.gc.service.IBusGcUserOpenGameService;
import com.kantboot.system.user.service.IUserSelfService;
import com.kantboot.util.core.param.PageParam;
import com.kantboot.util.core.result.PageResult;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BusGcUserOpenGameServiceImpl implements IBusGcUserOpenGameService {

    @Resource
    private BusGcUserOpenGameRepository repository;

    @Resource
    private IUserSelfService userSelfService;


    @Override
    public List<BusGcUserOpenGame> getByUserId(Long userId) {
        return repository.findByUserId(userId);
    }

    @Override
    public Boolean AddUserOpenGameService(Long gameId) {
        if (gameId == null) {
            return false;
        }
        System.out.println("gameId = " + gameId);
        Long selfId = userSelfService.getSelfId();
//        BusGcUserOpenGame userOpenGame = repository.findByUserIdAndGameId(selfId, gameId);
//        if (userOpenGame != null) {
//            return true;
//        }
        repository.save(new BusGcUserOpenGame().setUserId(selfId).setGameId(gameId));
        return true;
    }

    @Override
    public PageResult getBodyData(PageParam<BusGcCollectSearchUserDTO> pageParam) {
        return PageResult.of(repository.getBodyDataByUserId(pageParam.getData(), pageParam.getPageable()));
    }
}
